with ($ns("fp.caches"))
{
    fp.caches.ImageCacheClass = function()
    {
        var me = this;
        
        me.imageQueue = [];
        me.isBusy = false;
        
        var _$img = $("<img/>");
        
        me.init = function()
        {
            
        };
        
        me.cacheImage = function(p_url)
        {
            if (p_url != null && !me.imageQueue.contains(p_url))
            {
                me.imageQueue.add(p_url);
                
                if (!me.isBusy)
                {
                    _cacheImage();
                }
            }
        };
        
        me.cacheImages = function(p_images)
        {
            for (var i = 0; i < p_images.length; i++)
            {
                var image = p_images[i];
                me.cacheImage(image);
            }
        };
        
        
        
        
        
        
        
        
        var _$img = $("<img>");
        function _cacheImage()
        {
            if (me.imageQueue.length)
            {
                me.isBusy = true;
                var url = me.imageQueue[0];
                me.imageQueue.removeAt(0);
                _$img.one("load", _img_callback);
                _$img.one("error", _img_callback);
                _$img.attr("src", url);
            }
        }
        
        function _img_callback(e)
        {
            if (e.type == "load")
            {
                console.log("[" + e.target.src + "] cached, " + me.imageQueue.length + " left.");
            }
            else
            {
                console.error("[" + e.target.src + "] error, " + me.imageQueue.length + " left.");
            }
            if (me.imageQueue.length == 0)
            {
                me.isBusy = false;
            }
            else
            {
                _cacheImage();
            }
        }
        
        return me;
    };
    
    fp.caches.ImageCache = new fp.caches.ImageCacheClass();
    fp.caches.ImageCache.init();
}